﻿using System;
using System.Windows.Forms;

namespace WaterResources
{
    public partial class FormHome : Form
    {
        public bool status = true;
        public FormHome()
        {
            InitializeComponent();
            var db = new WaterMakeTimeDb<WaterMakeTime>();
            var wsSource = db.FindFirst();
            if (wsSource == null) {
                var ws = new WaterMakeTime
                {
                    Time = DateTime.Now
                };
                db.Save(ws);
                maketime.Text = "试用时长30天";
            }
            else {
                var a = DateTime.Now.Subtract(wsSource.Time).Days;
                int b = 30 - a;
                maketime.Text = "试用时长"+ b + "天";
                if (Convert.ToInt32(b) ==0) {
                    status = false;
                }
            }
        }

        private void buttonWaterSecurity_Click(object sender, EventArgs e)
        {
            if (status) { 
            var form = new FormWaterSecurity();
            form.Show();
            form.Activate();
            Hide();
            }
        }

        private void buttonWaterEnvironment_Click(object sender, EventArgs e)
        {
            if (status)
            {
                var form = new FormWaterEnvironment();
                form.Show();
                form.Activate();
                Hide();
            }
        }
    }
}
